package com.xingfudazi.web.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.xingfudazi.app.domain.AppAccount;
import com.xingfudazi.app.service.IAppAccountService;
import com.xingfudazi.common.annotation.Log;
import com.xingfudazi.common.core.controller.BaseController;
import com.xingfudazi.common.core.domain.AjaxResult;
import com.xingfudazi.common.core.page.TableDataInfo;
import com.xingfudazi.common.enums.BusinessType;
import com.xingfudazi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 账号Controller
 * 
 * @author ruoyi
 * @date 2024-06-21
 */
@RestController
@RequestMapping("/app/account")
public class AppAccountController extends BaseController
{
    @Autowired
    private IAppAccountService appAccountService;

    /**
     * 查询账号列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AppAccount appAccount)
    {
        startPage();
        List<AppAccount> list = appAccountService.selectAppAccountList(appAccount);
        return getDataTable(list);
    }

    /**
     * 导出账号列表
     */
    @Log(title = "账号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppAccount appAccount)
    {
        List<AppAccount> list = appAccountService.selectAppAccountList(appAccount);
        ExcelUtil<AppAccount> util = new ExcelUtil<AppAccount>(AppAccount.class);
        util.exportExcel(response, list, "账号数据");
    }

    /**
     * 获取账号详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appAccountService.selectAppAccountById(id));
    }

    /**
     * 新增账号
     */
    @Log(title = "账号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppAccount appAccount)
    {
        return toAjax(appAccountService.insertAppAccount(appAccount));
    }

    /**
     * 修改账号
     */
    @Log(title = "账号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppAccount appAccount)
    {
        return toAjax(appAccountService.updateAppAccount(appAccount));
    }

    /**
     * 删除账号
     */
    @Log(title = "账号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appAccountService.deleteAppAccountByIds(ids));
    }
}
